package breeze.lepei.der;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;
import breeze.lepei.der.utils.AppExceptionCacher;
import breeze.lepei.der.utils.MLog;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import android.os.Build;
import android.os.StrictMode;
import breeze.lepei.der.R;
import android.graphics.Color;
import java.lang.reflect.Field;
import android.graphics.Typeface;

public abstract class BaseView extends AppCompatActivity {
	
	public Context mContext;//全局Context
	public static ExecutorService exec;//全局线程池
	public static MLog mLog;//全局log
	private static final String TAG="BaseView";
	
	/**
	*@date 2020-10-18 9:03
	*@author BREEZE
	*@description 培个Der基础类
	*/
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext=this.getApplicationContext();
		//全局注册错误日志抓取
		Thread.setDefaultUncaughtExceptionHandler(AppExceptionCacher.getInstance(mContext));
		//初始化全局线程池
		exec=Executors.newCachedThreadPool();
		//初始化全局log
		mLog=new MLog(mContext);
		//适配安卓7
		if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
			StrictMode.VmPolicy.Builder builder=new StrictMode.VmPolicy.Builder();
			StrictMode.setVmPolicy(builder.build());
			builder.detectFileUriExposure();
		}
	}
	
	//初始化界面
	public abstract void init();
	public abstract void initData();
	
	/*
	*@author BREEZE
	*@description 获取实例化控件所需
	*@param 控件id
	*@return 控件实例
	*/
	public <T> T f(int viewId){
		return findViewById(viewId);
	}
	
	/**
	*@author BREEZE
	*@description 全局提示
	*@param 内容
	*/
	public void toast(final String message){
		runOnUiThread(new Runnable(){public void run(){
			Toast.makeText(mContext,message,Toast.LENGTH_LONG).show();
		}});
	}
	
	/**
	*@author BREEZE
	*@description 获取view
	*@param 布局id
	*@return 布局view
	*/
	public View getView(int layoutId){
		return LayoutInflater.from(mContext).inflate(layoutId,null);
	}
	
	/**
	*@author BREEZE
	*@description 初始化全局线程池
	*@param null
	*@return 线程池
	*/
	public static ExecutorService getExec(){
		if(exec==null){
			exec=Executors.newCachedThreadPool();
		}
		return exec;
	}
	
	/**
	*@author BREEZE
	*@description 适配状态栏
	*@param 颜色
	*/
	public void fitSystemStatusBar(int statusBarColor){
		if(Build.VERSION.SDK_INT>=21){
			getWindow().setStatusBarColor(statusBarColor);
			getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
		}
	}
	
	/**
	*@author BREEZE
	*@description 获取颜色
	*@param 十六进制颜色
	*@return 颜色
	*/
	public int getColor(String HexColor){
		return Color.parseColor(HexColor);
	}
	
}
